<template>
  <div class="app-container">

    <aside>
      <a>Alt+P</a>&nbsp;&nbsp;快捷键
      <br>
      <span class="demo-response" id="manage-window-reply"></span>
    </aside>

    <!--<div class="documentation-container">-->
      <!--<a class="document-btn" target="_blank">长: {{width}}</a>-->
      <!--<a class="document-btn" target="_blank">宽: {{height}}</a>-->
      <!--<a class="document-btn" target="_blank">横坐标: {{x}}</a>-->
      <!--<a class="document-btn" target="_blank">纵坐标: {{y}}</a>-->
    <!--</div>-->

  </div>
</template>
<script>

import path from 'path'
const BrowserWindow = require('electron').remote.BrowserWindow
import { getToken } from '@/utils/auth' // get token from cookie

export default {
  created() {
    console.log(localStorage.getItem('fc_window_switch'))
    if (localStorage.getItem('fc_window_switch') === 'off' || localStorage.getItem('fc_window_switch') === null ) {
      this.openFastCollect()
    }
  },
  data() {
    return {
      width : Number(localStorage.fast_collect_width),
      height : Number(localStorage.fast_collect_height),
      x : Number(localStorage.fast_collect_x),
      y : Number(localStorage.fast_collect_y)
    }
  },
  methods: {
    openFastCollect() {
      const modalPath = process.env.NODE_ENV === 'development'
        ? 'http://localhost:8080/#/fastCollect'
        : `file://${__dirname}/index.html#fastCollect`

      let win = new BrowserWindow({
        // transparent: true,
        // frame: true,
        width: this.width,
        height: this.height,
        minWidth: 200,
        minHeight: 500,
        maxWidth: 200,
        x: this.x,
        y: this.y,
        webPreferences: {
          webSecurity: false,
          nodeIntegration: true
        },
        autoHideMenuBar: true // 隐藏工具栏
      })
      win.on('resize', updateReply)
      win.on('move', updateReply)
      win.on('close', function() {
        win = null
        localStorage.setItem('fc_window_switch', 'off')
      })
      win.loadURL(modalPath)
      // 前置窗口
      win.setAlwaysOnTop(true)
      win.setOpacity(0.9)
      win.show()

      localStorage.setItem('fc_window_switch', 'on')

      function updateReply() {
        const manageWindowReply = document.getElementById('manage-window-reply')
        const message = `Size: ${win.getSize()} Position: ${win.getPosition()}`
        manageWindowReply.innerText = message

        localStorage.setItem('fast_collect_width', win.getSize()[0])
        localStorage.setItem('fast_collect_height', win.getSize()[1])
        localStorage.setItem('fast_collect_x', win.getPosition()[0])
        localStorage.setItem('fast_collect_y', win.getPosition()[1])
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
